//
//  DGGTheme.m
//  DGGThemKit
//
//  Created by 胡中楷 on 2020/4/4.
//

#import "DGGSwizzleTools.h"
#include <objc/runtime.h>

@implementation DGGSwizzleTools

void dl_swizzleMethod(Class objClass, SEL originalSelector, SEL swizzledSelector){
    // the method might not exist in the class, but in its superclass
    Method originalMethod = class_getClassMethod(objClass, originalSelector);
    Method swizzledMethod = class_getClassMethod(objClass, swizzledSelector);
    // class_addMethod will fail if original method already exists
//    BOOL didAddMethod = class_addMethod(objClass, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
//    // the method doesn’t exist and we just added one
//    if (didAddMethod) {
//        class_replaceMethod(objClass, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
//    }else {
        method_exchangeImplementations(originalMethod, swizzledMethod);
    //}
}

@end
